import { Component } from 'react'
import "../assent/css/register.css"
import logo from "../assent/img/mine/lo.png"
import React from 'react';

// 引入注册接口
import { doregister } from "../request/app"
class Register extends Component {
    constructor() {
        super()
        // 数据
        this.state = {
            title: "注册",
            userinfo: {
                phone: "",
                password: "",
                nickname: ""
            }
        }
    }


    render() {

        // 结构
        let { phone, nickname, password } = this.state.userinfo
        return (
            <div id='logins'>
                <h1 className='mine'>注册</h1>
                <div className='bga'>
                    <img src={logo} /></div>
                <div className='log'>
                    <div className='zh'>
                        <input type="text" placeholder='请输入账号' value={phone} onChange={this.change.bind(this, "phone")} />
                    </div>
                    <div className='zh'>
                        <input type="text" placeholder='请输入密码' value={nickname} onChange={this.change.bind(this, "nickname")} />

                    </div>
                    <div className='zh'>
                        <input type="text" placeholder='请输入用户名' value={password} onChange={this.change.bind(this, "password")} />

                    </div>
                    <div className='o'>
                        <a href="/login" className='click'>点击去登录</a>
                    </div>
                </div>

                <p className='login' onClick={this.register.bind(this)}>注册</p>
            </div>
        );
    }
    // 手机号，昵称，密码
    change(type, e) {
        this.setState({
            userinfo: {
                ...this.state.userinfo,
                [type]: e.target.value
            }
        })
    }
    // 执行注册
    register() {
        if (this.state.userinfo.phone == "" || this.state.userinfo.nickname== ""||this.state.userinfo.password== "") {
            alert("请输入正确的内容")
            return
        }
        // 注册向后台传参
        doregister(this.state.userinfo).then(res => {
            console.log(res, "注册")
            alert(res.msg)

            if (res.code != 200) {
                return
            }
            window.location.href = "/login"

        })

        // console.log(this.state.userinfo);
    }
}
export default Register